#ifndef __LIB_SURPORT_H_H_
#define __LIB_SURPORT_H_H_

#include "stdint.h"
#include "stdlib.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define ICTYPE_STM32F10X 0x0F103   
#define ICTYPE_STM32F4XX 0x0F407   
#define ICTYPE_STM32H750 0x0E750   

#define ICTYPE_APM32F003 0x1F003 
#define ICTYPE_APM32F030 0x1F030 

#define ICTYPE_AT32F421 0xAF421  
#define ICTYPE_AT32F423 0xAF423
#define ICTYPE_AT32F415 0xAF415
#define ICTYPE_AT32F402 0xAF402
#define ICTYPE_AT32F405 0xAF405
#define ICTYPE_AT32F437 0xAF437

#define ICTYPE_GD32E230  0xDE230  

#define ICTYPE_NUC029LAN 0xC029A
#define ICTYPE_NUC029LDE 0xC029E

#define ICTYPE_AT32F423_START 0xFF00A423 
#define ICTYPE_AT32F405_START 0xFF00A405 
#define ICTYPE_APM32F407_SELF 0xFF00F407 
#define ICTYPE_AT32F437_SELF  0xFF00A437
#define ICTYPE_APM32F411_TINY 0xFF00B411 
#define ICTYPE_APM32F407_TINY 0xFF00B407 
#define ICTYPE_STM32H533_NUCLEO 0xFF00F533 

	extern volatile uint16_t lib_tick16_cnt; 
	extern volatile uint32_t lib_tick32_cnt; 
	extern volatile uint16_t lib_tick16_div2_cnt;  
	extern volatile uint16_t lib_tick16_div4_cnt;  
	extern volatile uint16_t lib_tick16_div8_cnt;  
	extern volatile uint16_t lib_tick16_scnt;      
	extern volatile uint16_t cpu_freq_mhz;

	void lib_delay_0_5us(uint16_t u0_5us);
	void lib_delay_us(uint16_t us);
	void lib_delay_ms(uint16_t us);
	void *lib_malloc(size_t size);
	void lib_free(void *);

	int32_t lib_chk_get(void); 
	int32_t lib_chk_err_type(void); 
	int32_t lib_chk_test(void); 

#define DEV_ERR_NONE 0
#define DEV_ERR_LIMIT_AMOUNT 1
#define DEV_ERR_LRC 2
#define DEV_ERR_NLRC 3
#define DEV_ERR_CPUID 4
#define DEV_ERR_SRC1 5
#define DEV_ERR_SRC2 6
#define DEV_ERR_SUM 7
#define DEV_ERR_ROM_SIZE 8
#define DEV_ERR_ICTYPE 10
#define DEV_ERR_DIV 12
#define DEV_ERR_CRC 13
#define DEV_ERR_ROM_FLAG1 15
#define DEV_ERR_ROM_FLAG2 16

#define DEV_ERR_CLOCK1 20
#define DEV_ERR_CLOCK2 21
#define DEV_ERR_CLOCK3 22
#define DEV_ERR_CLOCK4 23
#define DEV_ERR_CLOCK5 24
#define DEV_ERR_CLOCK6 25
#define DEV_ERR_CLOCK7 26
#define DEV_ERR_CLOCK8 27
#define DEV_ERR_CLOCK9 28
#define DEV_ERR_CLOCK10 29

#define DEV_ERR_PORT1 30
#define DEV_ERR_PORT2 31
#define DEV_ERR_PORT3 32
#define DEV_ERR_PORT4 33
#define DEV_ERR_PORT5 34
#define DEV_ERR_PORT6 35
#define DEV_ERR_PORT7 36
#define DEV_ERR_PORT8 37
#define DEV_ERR_PORT9 38
#define DEV_ERR_PORT10 39

#define DEV_ERR_REG1 40
#define DEV_ERR_REG2 41
#define DEV_ERR_REG3 42
#define DEV_ERR_REG4 43
#define DEV_ERR_REG5 44
#define DEV_ERR_REG6 45
#define DEV_ERR_REG7 46
#define DEV_ERR_REG8 47
#define DEV_ERR_REG9 48
#define DEV_ERR_REG10 49

#define DEV_ERR_ICVAL1 50
#define DEV_ERR_ICVAL2 51

#ifdef __cplusplus
}
#endif

#endif 
